package anatex.domain;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import anatex.domain.*;
import javax.persistence.OneToOne;
import javax.persistence.TypedQuery;
import java.util.List;

@RooJavaBean
@RooToString
@RooEntity
public class TrainingDocument {

    @OneToOne
    private Document document;
    
    public static List<TrainingDocument> findTrainingDocumentByUserAndDomain (Users u, DocumentDomain dd) {
    	TypedQuery<TrainingDocument> q = entityManager().createQuery("select td from TrainingDocument td "
    			+ "join td.document d "
    			+ "join d.documentDomain dd "
    			+ "where d.owner = :u and d.documentDomain = :dd", TrainingDocument.class);
    	q.setParameter("u", u);
    	q.setParameter("dd", dd);
    	
    	return q.getResultList();
    }
    
}
